package game;

public class ButtonLogic {
	
	private static ButtonLogic instance;
	
	public static ButtonLogic getInstace()
	{
		if(instance == null)
			instance = new ButtonLogic();
			
		return instance;
	}
	
	public MatrixCell NumberLogic(MatrixCell matrix, int indexNumber)
	{
		if (matrix.value == null)
		{
			matrix.value = "" + indexNumber;
			matrix.i += 1;
		}
		else
		{
			if (matrix.i < 2 && matrix.value.contains(".") == false)
			{
				matrix.value += "" + indexNumber;
				matrix.i += 1;
			}
			else if (matrix.d < 2 && matrix.value.contains(".") == true)
			{
				matrix.value += "" + indexNumber;
				matrix.d += 1;
			}

		}
		return matrix;
	}
	
	public MatrixCell SignLogic (MatrixCell matrix, int type)
	{
		if (matrix.value != null)
			switch (type)
			{
				case 0:
					if (Double.parseDouble(matrix.value) < 0)
						matrix.value.replace("-", "+");
					break;
				case 1:
					if (Double.parseDouble(matrix.value) > 0)
						matrix.value = "-" + Math.abs(Double.parseDouble(matrix.value));
					break;
			}
			
		return matrix;
	}
	
	public MatrixCell CommaLogic(MatrixCell matrix)
	{
		if (matrix.value == null)
			matrix.value = "0.";
		else if (matrix.value.contains(".") == false)
			matrix.value += ".";
		
		return matrix;
	}
}
